import os
from schedule import every, repeat, run_pending
import time
import pytest
from common.yaml_util import *
from loguru import logger


@repeat(every().day.at("21:00"))
@repeat(every(20 * 60).seconds)
@logger.catch
def open_door():
    execution_date_start = time.strftime("%Y/%m/%d %H:%M:%S")
    clear_yaml('临时变量.yaml')
    write_yaml({'起始时间': execution_date_start}, '临时变量.yaml')
    logger.info('开始执行脚本！！', execution_date_start)
    pytest.main()


if __name__ == '__main__':
    logger.add("runtime.log", rotation="200 MB", retention="3 days")
    while True:
        run_pending()
        # open_door()

    # open_door()
    # 生成报告
    # time.sleep(3)
    # os.system('allure generate ./temp -o ./report --clean')



